/**   
* @Title: WechatTimer.java 
* @Package com.leesche.zcsp.node.pay.wecha.timer 
* @Description:() 
* @author dennies yang
* @date 2016年10月12日 下午3:15:52 
* @version V1.0   
*/
package com.leesche.zcsp.node.pay.wecha.timer;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.leesche.zcsp.node.pay.wecha.data.AccessToken;
import com.leesche.zcsp.node.pay.wecha.data.Message;
import com.leesche.zcsp.node.pay.wecha.data.WechatJsToken;
import com.leesche.zcsp.node.pay.wecha.service.WechatService;
import com.leesche.zcsp.node.pay.wecha.service.encha.impl.WechatServiceImpl;

/**   
* @Title: WechatTimer.java 
* @Package com.leesche.zcsp.node.pay.wecha.timer 
* @Description:(定时更新token) 
* @author dennies yang
* @date 2016年10月12日 下午3:15:52 
* @version V1.0   
*/
@Component
@Lazy(value=false)
public class WechatTimer   {
	private final static Logger LOGGER = Logger.getLogger(WechatTimer.class);

	public static  String ASSCEE_TOKEN="";
	public static  String JS_TIKET="";
	@Autowired
	WechatService wechatService;
 

  	@Scheduled(fixedRate = 1000*60*60*2)
	public void doWechatTimer() {
		Message<AccessToken>  am=wechatService.getWechatAccessToken();
		if(Message.isError(am.getType())){
			LOGGER.error(am.toString());
		}else {
			ASSCEE_TOKEN=am.getContent().getAccess_token();
			if(StringUtils.isNotBlank(ASSCEE_TOKEN)){
				Message<WechatJsToken> jsm=wechatService.getWechatJsToken(ASSCEE_TOKEN);
				if(Message.isError(jsm.getType())){
					LOGGER.error(am.toString());
				}
				JS_TIKET=jsm.getContent().getTicket();
			}
		}
		LOGGER.info("token === " +ASSCEE_TOKEN);
		LOGGER.info("JS_TIKET === " +JS_TIKET);
		
		
	}



}
